package petrus.components.properties 
{
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author Mariusz Cwilag
	 */
	public class Properties extends EventDispatcher 
	{	
		public var id		:String;
		public var width	:Number;
		public var height	:Number;
		
		protected var properties :Dictionary;
		
		public function Properties()
		{
			properties = new Dictionary();
		}
		
		/**
		 * 
		 * @return Array
		 */
		public function getProperties():Array 
		{
			var tmp : Array = [];
			var prop : String;
			for (prop in properties)
				tmp.push(prop);
			return tmp;
		}
		
		/**
		 * 
		 * @param	key
		 * @param	defaultValue
		 * @return	String
		 */
		public function getProperty(key:String, defaultValue:String = null):String 
		{
			var val : String = String(properties[key]);
			if (val == null && defaultValue != null)
				val = properties[key] = defaultValue;
			return val;
		}
		
		/**
		 * 
		 * @param	key
		 * @param	value
		 * @return	String
		 */
		public function setProperty(key:String, value:*):String 
		{
			return put(key, value);
		}
		
		/**
		 * 
		 * @param	key
		 * @param	value
		 * @return  String
		 */
		protected function put(key:String, value:*):String 
		{
			if (properties == null)
				properties = new Dictionary();
			var p:String = properties[key];
			properties[key] = value;
			return p;	    	
		}
		
		/**
		 * 
		 * @param	key
		 * @return  Boolean
		 */
		public function hasProperty(key:String):Boolean 
		{
			var prop:String;
			for (prop in properties) {
				if (prop == key)
					return true;
			}
			return false;
		}
		
		/**
		 * 
		 * @param	property
		 * @return  String
		 */
		public function removeProperty(property:String):String 
		{
			var p:String = properties[property];
			delete properties[property];
			return p;	    	
		}
	}
}